/**
 * @file usr_pd_i2c.h
 * @author 黑马小乌龟 (532352406@qq.com)
 * @brief 
 * @version 0.1
 * @date 2025-10-11
 * 
 * @copyright Copyright (c) 2025
 * 
 */
#ifndef USR_PD_I2C__H_H
#define USR_PD_I2C__H_H

#ifdef __cplusplus
extern "C"{
#endif
#include<stdint.h>
#include<stdio.h>



#include "hc32_ll.h"
#include "ev_hc32f334_lqfp64_bsp.h"

#define CFG_PD_I2C_SLAVE_ADDR (0X56>>1)

#define USB_IN_FLG 0X10
#define DC_IN_FLG  0x08

/** PD芯片内部 I2C reg map 
 * 
 * REG 0(RO): PD协议芯片内部固件版本信息, 格式: BCD code ,例如： V1.0==> 0x10, V1.3==>0x13;
 * REG 1(RO): 输入源信息
 *          b7~b5: Reserved  
 *          b4: 1 => USB Input active; 0 => USB input inactive
 *          b3: 1 => DC Input active; 0 => DC input inactive
 *          b2~b0: USB input information
 *                  000: unknown
 *                  001: PD2.0
 *                  010: BC1.2
 *                  011: QC2.0
 *                  100: QC3.0
 *                  101: PD3.0
 *                  110: CDP
 *                  111: SDP
 *                    
 * REG 2(RW): 配置PD/QC交互信息
 *          b7~b4: Reserved
 *          b3~b0: 配置输入电压
 *              0000: 5V
 *              0001: 9V
 *              0010: 12V
 *              0011: 15V
 *              0100: 20V
 *          
 * 
*/
typedef enum {
// *          b2~b0: USB input information
// *                  000: unknown
// *                  001: PD2.0
// *                  010: BC1.2
// *                  011: QC2.0
// *                  100: QC3.0
// *                  101: PD3.0
// *                  110: CDP
// *                  111: SDP
USB_INFOR_unknown=0,
USB_INFOR_PD2_0,
USB_INFOR_BC1_2,
USB_INFOR_QC2_0,
USB_INFOR_QC3_0,
USB_INFOR_PD3_0,
USB_INFOR_CDP,
USB_INFOR_SDP,
}USB_INPUT_INFOR;

typedef enum{
//  *          b3~b0: 配置输入电压
//  *              0000: 5V
//  *              0001: 9V
//  *              0010: 12V
//  *              0011: 15V
//  *              0100: 20V
USB_IN_CFG_5V=0,
USB_IN_CFG_9V,
USB_IN_CFG_12V,
USB_IN_CFG_15V,
USB_IN_CFG_20V,

USB_IN_CFG_MAX_
}USB_INPUT_CFG;

#define PD_CHIP_INT_PORT GPIO_PORT_B
#define PD_CHIP_INT_PIN  GPIO_PIN_09

int32_t usr_PD_I2C_Write(uint16_t u16Addr, const uint8_t *pu8Buf, uint32_t u32Len);
int32_t usr_PD_I2C_Read(uint16_t u16Addr, uint8_t *pu8Buf, uint32_t u32Len);
void usb_pd_information_handle(uint8_t sync_flg);
void usb_pd_int_gpio_init(void);
#ifdef __cplusplus
}
#endif

#endif //USR_PD_I2C__H_H


